#include "StdAfx.h"
#include "capturer.h"
#include "capturer_p.h"

Capturer::Capturer(const uint index, QObject *parent)
	: QObject(parent)
	, d_ptr(new CapturerPrivate(index, this))
{

}

Capturer::Capturer(CapturerPrivate &dd, QObject *parent)
	: QObject(parent)
	, d_ptr(&dd)
{

}

Capturer::~Capturer()
{

}

uint Capturer::index() const
{
	return d_func()->index;
}

QPointF Capturer::position() const
{
	return d_func()->position;
}
void Capturer::setPosition(const QPointF& position)
{
	Q_D(Capturer);
	d->position = position;
}

QRect Capturer::viewport() const
{
	return d_func()->viewport;
}

void Capturer::setViewport(const QRect& viewport)
{
	Q_D(Capturer);
	d->viewport = viewport;
}

QSize Capturer::pixelRatio() const
{
	return d_func()->pixelRatio;
}

void Capturer::setPixelRatio(const QSize& pixelRatio)
{
	Q_D(Capturer);
	d->pixelRatio = pixelRatio;
}

bool Capturer::horizontalFlip() const
{
	return d_func()->horizontalFlip;
}

void Capturer::setHorizontalFlip(const bool horizontalFlip)
{
	Q_D(Capturer);
	d->horizontalFlip = horizontalFlip;
}

bool Capturer::verticalFlip() const
{
	return d_func()->verticalFlip;
}

void Capturer::setVerticalFlip(const bool verticalFlip)
{
	Q_D(Capturer);
	d->verticalFlip = verticalFlip;
}

SampleGrabberCallback* Capturer::sampleGrabberCallback() const
{
	return d_func()->sampleGrabberCallback;
}

bool Capturer::isOpened() const
{
	return d_func()->open;
}

bool Capturer::isRunning() const
{
	return d_func()->running;
}

void Capturer::open()
{
	Q_D(Capturer);
	d->open = true;
}

void Capturer::close()
{
	Q_D(Capturer);
	d->open = false;
}

void Capturer::start()
{
	Q_D(Capturer);
	d->running = true;
}

void Capturer::stop()
{
	Q_D(Capturer);
	d->running = false;
}

void Capturer::restart()
{
	if(isRunning())
		stop();
	start();
}

void Capturer::moveTo(const QPointF& position)
{
	Q_D(Capturer);
	QMutexLocker(&d->mutex);
	d->position = position;
}

VirtualCapturer::VirtualCapturer(const uint index, const QString& fileName, QObject* parent)
	: Capturer(*new VirtualCapturerPrivate(index,fileName,this),parent)
{

}

VirtualCapturer::~VirtualCapturer()
{

}

QString VirtualCapturer::fileName() const
{
	return d_func()->fileName;
}

void VirtualCapturer::setFileName(const QString& fileName)
{
	Q_D(VirtualCapturer);
	d->fileName = fileName;
}

QImage VirtualCapturer::grabImage() const
{
	return QImage();
}

void 
VirtualCapturer::moveTo(const QPointF& point)
{
	Q_D(VirtualCapturer);
	Capturer::moveTo(point);
	QMutexLocker(&d->mutex);
}